USE [wdms]
GO

-- =============================================
-- Author     :		Lohith Ram D V
-- Create date:         08/mar/2011
-- Description:	List Documents according to the user id.
-- =============================================

create procedure sp_ListDocumentByUserID(
	@par_userid int)
AS
BEGIN
	SELECT [Document].doc_title as [Title], [Document].doc_create_time as [Creation Time], [Document].doc_last_access as [Last Accessed Time], 
	[Document].doc_type as [Type], [User1].user1_name as [Author] 
	FROM [Document] INNER JOIN [User1] ON [Document].user1_id = [User1].user1_id and [Document].user1_id=@par_userid
	
	union
	
	SELECT [Document].doc_title as [Title], [Document].doc_create_time as [Creation Time], [Document].doc_last_access as [Last Accessed Time], 
	[Document].doc_type as [Type], [User1].user1_name as [Author] 
	FROM Doc_Share INNER JOIN [Document] ON Doc_Share.doc_id = [Document].doc_id INNER JOIN
                      [User1] ON Doc_Share.user_origin_id = [User1].user1_id and Doc_Share.user_target_id = @par_userid
END